package com.pactera.mavenweb.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.pactera.mavenweb.dao.GroupRoleDao;
import com.pactera.mavenweb.entity.GroupRole;
import com.pactera.mavenweb.service.GroupRoleService;

@Service("groupRoleService")
public class GroupRoleServiceImpl implements GroupRoleService {
	
	/**
	 * 注入dao
	 */
	@Resource(name = "groupRoleDao")
	private GroupRoleDao groupRoleDao;
	
//	@Override
	@SuppressWarnings("unchecked")
	public int saveGroupRoles(List<GroupRole> groupRoles) {
		try {
			for (GroupRole groupRole : groupRoles) {
				groupRoleDao.saveGroupRole(groupRole);
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		return 0;
	}
	
//	@Override
	@SuppressWarnings("unchecked")
	public List<GroupRole> getAllGroupRole() {
		return groupRoleDao.queryAll();
	}
	
//	@Override
	@SuppressWarnings("unchecked")
	public void addGroupRole(GroupRole groupRole) {
		groupRoleDao.saveGroupRole(groupRole);
	}
	
//	@Override
	@SuppressWarnings("unchecked")
	public boolean delGroupRole(int id) {
		
		groupRoleDao.delete(id);
		
		return true;
	}
	
//	@Override
	@SuppressWarnings("unchecked")
	public void updateGroupRole(GroupRole groupRole) {
		groupRoleDao.update(groupRole);
	}
	
//	@Override
	@SuppressWarnings("unchecked")
	public GroupRole getGroupRole(String id) {
		return groupRoleDao.queryById(id);
	}
	
//	@Override
	@SuppressWarnings("unchecked")
	public List<GroupRole> getRolesFromGroupId(int groupId) {
		String hql = "from GroupRole where group_id = ?";
		Object[] idArray = {groupId};
		
		return groupRoleDao.queryForList(hql, idArray);
	}
}